package com.program.beautymakeup.controller;

import com.program.beautymakeup.controller.form.UploadPortfolioForm;
import com.program.beautymakeup.domain.vo.ResultInfo;
import com.program.beautymakeup.service.UploadService;
import com.program.beautymakeup.utils.ResultInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author bytedance
 * @ClassName UploadController.java
 * @Description 文件的所有操作
 * @createTime 2023年02月07日 00:10:00
 */
@RestController
@RequestMapping("/file")
@Slf4j
public class FileController {
    @Autowired
    private UploadService uploadService;

    @PostMapping("/uploadImg")
    public ResultInfo uploadImg(@ModelAttribute UploadPortfolioForm form){
        MultipartFile file = form.getFileList().get(0);
        log.info("[开始上传文件],file_size:{},filename:{}",file.getSize(),file.getOriginalFilename());
        return ResultInfoUtil.buildSuccess("上传成功", uploadService.uploadImg(form.getFileList()));
    }

    @PostMapping("/uploadPortfolios")
    public ResultInfo uploadPortfolios(@ModelAttribute UploadPortfolioForm form)  {
        return uploadService.uploadPortfolios(form);
    }

    @DeleteMapping("/delFile")
    public ResultInfo deleteFile(@RequestBody List<String> urls) {
        return ResultInfoUtil.buildSuccess(uploadService.deleteFile(urls));
    }
}

